package com.example.student.controller;
import com.example.student.pojo.PageBean;
import com.example.student.pojo.Result;
import com.example.student.pojo.Score;
import com.example.student.pojo.Stu;
import com.example.student.service.ScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学生成绩管理Controller
 */
@Slf4j
@RestController

public class ScoreController {
    @Autowired
    ScoreService scoreService;
    //查询所有学生成绩信息
//    @GetMapping("/score")
//    public Result list() {
//        log.info("查询所有数据");
//        List<Score> scores=scoreService.list();
//        return Result.success(scores);
//    }

    //根据id删除学生成绩信息
    @DeleteMapping("/score/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("根据{}删除学生成绩",id);
        scoreService.delete(id);
        return Result.success();}

    //修改学生成绩信息
    @GetMapping("/score/{id}")
    public Result getByID(@PathVariable Integer id) {
        log.info("获取学生ID:{}",id);
        Score score = scoreService.getByID(id);
        return Result.success(score);
    }
    @PutMapping("/score")
    public Result update(@RequestBody Score score) {
        log.info("修改学生成绩信息:{}",score);
        scoreService.update(score);
        return Result.success();
    }
    @GetMapping("/allScore")
    public Result page(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize) {
        PageBean pageBean=scoreService.page(page,pageSize);

        return Result.success(pageBean);
    }


    @GetMapping("/findScore")
    public Result pages(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize,
                       Integer studentId,String name) {
        PageBean pageBean=scoreService.pages(page,pageSize,studentId,name);
        return Result.success(pageBean);
    }

    @GetMapping("/classScore")
    public Result page(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize,Integer deptId) {
        PageBean pageBean=scoreService.classPage(page,pageSize,deptId);
        return Result.success(pageBean);
    }

    @GetMapping("/scoreRank")
    public Result scoreRank(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize) {
        PageBean pageBean=scoreService.rankPage(page,pageSize);
        return Result.success(pageBean);
    }
}
